/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package View;

import Control.ControlPet;
import Entity.Owner;
import java.util.Date;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Nicolas
 */
public class OwnerInfoPanel extends javax.swing.JPanel {

    private Owner owner;
    
    public OwnerInfoPanel(Owner owner, boolean update) {
        initComponents();
        this.owner=owner;
        name_text.setText(owner.getName());
            lastname_text.setText(owner.getLastName());
            ssn_text.setText(owner.getSSN());
            bdate_text.setText(owner.getBirthDate().toString());
            bplace_text.setText(owner.getBirthPlace());
            total.setText(owner.getTotalSpent());
        if(!update){
            name_text.setEditable(false);
            lastname_text.setEditable(false);
            ssn_text.setEditable(false);
            bdate_text.setEditable(false);
            bplace_text.setEditable(false);
            total.setEditable(false);        
        }
            for(int x = 0; x<owner.getPets().size();x++){
                if(x<pets_table.getRowCount()){
                pets_table.setValueAt(owner.getPets().get(x).getName(), x, 0);
                pets_table.setValueAt("charges", x, 1);
                }else{
                    DefaultTableModel model = (DefaultTableModel) pets_table.getModel();
                model.addRow(new Object[]{owner.getPets().get(x).getName(),"charges"});
                }
            }
       
    }

    public void updateOwner(){
        owner.setName(name_text.getText());
        owner.setLastName(lastname_text.getText());
        owner.setSSN(ssn_text.getText());
        owner.setBirthDate(new Date(bdate_text.getText()));
        owner.setBirthPlace(bplace_text.getText());
        
    }
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        name_text = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        lastname_text = new javax.swing.JTextField();
        ssn_text = new javax.swing.JTextField();
        bdate_text = new javax.swing.JTextField();
        bplace_text = new javax.swing.JTextField();
        total = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        pets_table = new javax.swing.JTable();

        setMaximumSize(new java.awt.Dimension(465, 284));
        setMinimumSize(new java.awt.Dimension(465, 284));
        setPreferredSize(new java.awt.Dimension(465, 284));

        jLabel1.setText("Owner");

        jLabel2.setText("Name");

        name_text.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                name_textActionPerformed(evt);
            }
        });

        jLabel3.setText("Last Name");
        jLabel3.setMaximumSize(new java.awt.Dimension(27, 14));
        jLabel3.setMinimumSize(new java.awt.Dimension(27, 14));
        jLabel3.setPreferredSize(new java.awt.Dimension(27, 14));

        jLabel4.setText("SSN");
        jLabel4.setMaximumSize(new java.awt.Dimension(27, 14));
        jLabel4.setMinimumSize(new java.awt.Dimension(27, 14));
        jLabel4.setPreferredSize(new java.awt.Dimension(27, 14));

        jLabel5.setText("BirthDate");
        jLabel5.setMaximumSize(new java.awt.Dimension(27, 14));
        jLabel5.setMinimumSize(new java.awt.Dimension(27, 14));
        jLabel5.setPreferredSize(new java.awt.Dimension(27, 14));

        jLabel6.setText("BirthPlace");
        jLabel6.setMaximumSize(new java.awt.Dimension(27, 14));
        jLabel6.setMinimumSize(new java.awt.Dimension(27, 14));
        jLabel6.setPreferredSize(new java.awt.Dimension(27, 14));

        jLabel7.setText("Total Spent");

        lastname_text.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                lastname_textActionPerformed(evt);
            }
        });

        pets_table.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null}
            },
            new String [] {
                "Pets", "Charge"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(pets_table);
        pets_table.getColumnModel().getColumn(1).setResizable(false);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(total, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 67, Short.MAX_VALUE))
                            .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(lastname_text, javax.swing.GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE)
                            .addComponent(ssn_text, javax.swing.GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE)
                            .addComponent(bdate_text, javax.swing.GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE)
                            .addComponent(bplace_text)
                            .addComponent(name_text))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 253, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(name_text, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lastname_text, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(ssn_text, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(bdate_text, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(bplace_text, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 12, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7)
                            .addComponent(total, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(89, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                        .addGap(19, 19, 19))))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void lastname_textActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_lastname_textActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_lastname_textActionPerformed

    private void name_textActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_name_textActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_name_textActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField bdate_text;
    private javax.swing.JTextField bplace_text;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField lastname_text;
    private javax.swing.JTextField name_text;
    private javax.swing.JTable pets_table;
    private javax.swing.JTextField ssn_text;
    private javax.swing.JTextField total;
    // End of variables declaration//GEN-END:variables

    /**
     * @return the owner
     */
    public Owner getOwner() {
        return owner;
    }

    /**
     * @param owner the owner to set
     */
    public void setOwner(Owner owner) {
        this.owner = owner;
    }

    /**
     * @return the bdate_text
     */
    public javax.swing.JTextField getBdate_text() {
        return bdate_text;
    }

    /**
     * @param bdate_text the bdate_text to set
     */
    public void setBdate_text(javax.swing.JTextField bdate_text) {
        this.bdate_text = bdate_text;
    }

    /**
     * @return the bplace_text
     */
    public javax.swing.JTextField getBplace_text() {
        return bplace_text;
    }

    /**
     * @param bplace_text the bplace_text to set
     */
    public void setBplace_text(javax.swing.JTextField bplace_text) {
        this.bplace_text = bplace_text;
    }

    /**
     * @return the jLabel1
     */
    public javax.swing.JLabel getjLabel1() {
        return jLabel1;
    }

    /**
     * @param jLabel1 the jLabel1 to set
     */
    public void setjLabel1(javax.swing.JLabel jLabel1) {
        this.jLabel1 = jLabel1;
    }

    /**
     * @return the jLabel2
     */
    public javax.swing.JLabel getjLabel2() {
        return jLabel2;
    }

    /**
     * @param jLabel2 the jLabel2 to set
     */
    public void setjLabel2(javax.swing.JLabel jLabel2) {
        this.jLabel2 = jLabel2;
    }

    /**
     * @return the jLabel3
     */
    public javax.swing.JLabel getjLabel3() {
        return jLabel3;
    }

    /**
     * @param jLabel3 the jLabel3 to set
     */
    public void setjLabel3(javax.swing.JLabel jLabel3) {
        this.jLabel3 = jLabel3;
    }

    /**
     * @return the jLabel4
     */
    public javax.swing.JLabel getjLabel4() {
        return jLabel4;
    }

    /**
     * @param jLabel4 the jLabel4 to set
     */
    public void setjLabel4(javax.swing.JLabel jLabel4) {
        this.jLabel4 = jLabel4;
    }

    /**
     * @return the jLabel5
     */
    public javax.swing.JLabel getjLabel5() {
        return jLabel5;
    }

    /**
     * @param jLabel5 the jLabel5 to set
     */
    public void setjLabel5(javax.swing.JLabel jLabel5) {
        this.jLabel5 = jLabel5;
    }

    /**
     * @return the jLabel6
     */
    public javax.swing.JLabel getjLabel6() {
        return jLabel6;
    }

    /**
     * @param jLabel6 the jLabel6 to set
     */
    public void setjLabel6(javax.swing.JLabel jLabel6) {
        this.jLabel6 = jLabel6;
    }

    /**
     * @return the jLabel7
     */
    public javax.swing.JLabel getjLabel7() {
        return jLabel7;
    }

    /**
     * @param jLabel7 the jLabel7 to set
     */
    public void setjLabel7(javax.swing.JLabel jLabel7) {
        this.jLabel7 = jLabel7;
    }

    /**
     * @return the jScrollPane1
     */
    public javax.swing.JScrollPane getjScrollPane1() {
        return jScrollPane1;
    }

    /**
     * @param jScrollPane1 the jScrollPane1 to set
     */
    public void setjScrollPane1(javax.swing.JScrollPane jScrollPane1) {
        this.jScrollPane1 = jScrollPane1;
    }

    /**
     * @return the lastname_text
     */
    public javax.swing.JTextField getLastname_text() {
        return lastname_text;
    }

    /**
     * @param lastname_text the lastname_text to set
     */
    public void setLastname_text(javax.swing.JTextField lastname_text) {
        this.lastname_text = lastname_text;
    }

    /**
     * @return the name_text
     */
    public javax.swing.JTextField getName_text() {
        return name_text;
    }

    /**
     * @param name_text the name_text to set
     */
    public void setName_text(javax.swing.JTextField name_text) {
        this.name_text = name_text;
    }

    /**
     * @return the pets_table
     */
    public javax.swing.JTable getPets_table() {
        return pets_table;
    }

    /**
     * @param pets_table the pets_table to set
     */
    public void setPets_table(javax.swing.JTable pets_table) {
        this.pets_table = pets_table;
    }

    /**
     * @return the ssn_text
     */
    public javax.swing.JTextField getSsn_text() {
        return ssn_text;
    }

    /**
     * @param ssn_text the ssn_text to set
     */
    public void setSsn_text(javax.swing.JTextField ssn_text) {
        this.ssn_text = ssn_text;
    }

    /**
     * @return the total
     */
    public javax.swing.JTextField getTotal() {
        return total;
    }

    /**
     * @param total the total to set
     */
    public void setTotal(javax.swing.JTextField total) {
        this.total = total;
    }


}
